package net.bithappens.hnqe.scratchpad;

import java.net.URI;
import java.util.Collection;
import java.util.Iterator;

import net.bithappens.hnqe.cache.ICacheTraverse;
import net.bithappens.hnqe.graph.GraphElement;
import net.bithappens.hnqe.graph.GraphNode;
import net.bithappens.hnqe.impl.cache.CacheManager;
import net.bithappesn.hnqe.traverse.GraphPath;

public class TestPathFinding {

	public static void main(String[] args) throws Exception {
		CacheManager manager = new CacheManager();
		ICacheTraverse traverser = manager;
		
		GraphNode start = new GraphNode("Service", new URI("http://sose.com/node/service31"), null);
		GraphNode end = new GraphNode("SoftwareBasedService", new URI("http://sose.com/node/softwarebasedservice14"), null);
		
		
		System.out.println("\n\n\n######################################################################################\n\n\n");
		
		long now = System.currentTimeMillis();
		
		Collection<GraphPath> allPaths = traverser.findPath("sose", start, end, 5, true, "SimpleTypeValidator", new Object[]{"TypeA", "TypeB"});

		System.out.println("elapsed time: "+(System.currentTimeMillis()-now));

		if(allPaths != null){
			for(GraphPath path : allPaths){
				Iterator<GraphElement> iter = path.getPathIterator();
				while(iter.hasNext()){
					System.out.println(iter.next());
				}
			}	
		}
		
		
		System.out.println("\n\n\n######################################################################################\n\n\n");
		
		
		start = new GraphNode("Service", new URI("http://sose.com/node/service10"), null);
		end = new GraphNode("HumanProvidedService", new URI("http://sose.com/node/humanprovidedservice8"), null);
		
		now = System.currentTimeMillis();
		allPaths = traverser.findPath("sose", start, end, 8, true, "SimpleTypeValidator", new Object[]{"TypeA", "TypeB", "TypeC"});
		System.out.println("elapsed time: "+(System.currentTimeMillis()-now));

		if(allPaths != null){
			for(GraphPath path : allPaths){
				Iterator<GraphElement> iter = path.getPathIterator();
				while(iter.hasNext()){
					System.out.println(iter.next());
				}
			}	
		}
		
		
		
		
		manager.stop();
	}
}
